<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加/修改到账</title>
<%@ include file="/view/common/tags.jsp"%>
</head>
<body>
	<div class="well well_p" style="margin-top: 35px;">
		<sk:form method="post" cssClass="form-horizontal" action="" id="saveAndUpdateFrom" target="_parent"  enctype="multipart/form-data">
			<div class="form-group">
				<label class="col-xs-2 text-right">游戏：</label>
				<div class="col-xs-3">
                    <sk:select cssClass="form-control select" name="gameId" id="gameId" value="" requiredInit="true" ajaxURL="${userInfoV1}/baseGame/gameSelect?wm[USE_FLAG]=1" onchange="TagUtil.fillOptions('gameId')">
                        <option value="">请选择</option>
                    </sk:select>
                    <input type="hidden" name="gameName" id="gameName" value=""/>
				</div>
                <label class="col-xs-1">&nbsp;</label>
                <label class="col-xs-2 text-right">交易类型：</label>
                <div class="col-xs-3">
                    <sk:select cssClass="form-control select" id="tradeId" name="tradeId" value="" parentCascadedSelect="gameId" parentParamName="gameId" requiredInit="true" ajaxURL="${tradeV1}/tradeState/gameTradeTypeDictList">
                        <option value="">请选择</option>
                    </sk:select>
                    <input type="hidden" name="tradeName" id="tradeName" value=""/>
                </div>
            </div>
            <div class="form-group" >
                <label class="col-xs-2 text-right">商品主类：</label>
                <div class="col-xs-3">
                    <sk:select cssClass="form-control select" id="baseTypeId" name="baseTypeId" value="" parentCascadedSelect="gameId" parentParamName="wm[GAME_ID]" ajaxURL="${userInfoV1}/gameGoodsType/baseTypeSelect?wm[OPEN_FLAG]=1&wm[DEL_FLAG]=0" onchange="setAjxaUrl('bigTypeId', 'gameId'); TagUtil.fillOptions('baseTypeId');">
                        <option value="">请选择</option>
                    </sk:select>
                    <input type="hidden" name="baseTypeName" id="baseTypeName" value=""/>
                </div>
                <label class="col-xs-1">&nbsp;</label>
                <label class="col-xs-2 text-right">商品大类：</label>
                <div class="col-xs-3">
                    <sk:select cssClass="form-control select" id ="bigTypeId" name="bigTypeId" value="" parentCascadedSelect="baseTypeId" parentParamName="wm[TYPE_FLAG]" ajaxURL="${userInfoV1}/gameGoodsType/typeSelect?wm[OPEN_FLAG]=1&wm[DEL_FLAG]=0" onchange="setAjxaUrl('smallTypeId', 'gameId'); TagUtil.fillOptions('bigTypeId')">
                        <option value="">请选择</option>
                    </sk:select>
                    <input type="hidden" name="bigTypeName" id="bigTypeName" value=""/>
                </div>
            </div>
            <div class="form-group" >
                <label class="col-xs-2 text-right">商品小类：</label>
                <div class="col-xs-3">
                    <sk:select cssClass="form-control select" id ="smallTypeId" name="smallTypeId" value="" parentCascadedSelect="bigTypeId" parentParamName="wm[PARENT_ID]" ajaxURL="${userInfoV1}/gameGoodsType/smallTypeSelect?wm[OPEN_FLAG]=1&wm[DEL_FLAG]=0">
                        <option value="">请选择</option>
                    </sk:select>
                    <input type="hidden" name="smallTypeName" id="smallTypeName" value=""/>
                </div>
                <label class="col-xs-1">&nbsp;</label>
                <label class="col-xs-2 text-right">到账时间：</label>
                <div class="col-xs-3">
                    <input id="ysLimit" name="ysLimit" class="form-control" style="width: 110px;display:inline-block"/>
                    <span calss="text-left">分</span>
                </div>
            </div>
 			<input type="hidden" id="rowId" name="rowId" value="<%=request.getParameter("rowId")%>">
           	<input type="hidden" id="token" name="token" value="">
           	<input type="hidden" id="isReCommit" value="0">
		</sk:form>	
	</div>
</body>
<%@ include file="/view/common/footer.jsp"%>
<script type="text/javascript">

$(function(){
	$("#token").val(sessionStorage.getItem("token"));
	
	$("#openStateOn").prop("checked", true);
	var rowId = $("#rowId").val();
	if(rowId > 0){
    	$.ajax({
            url: "${tradeV1}/tradeBaseToAccountSafetyConfig/getInfo",
            type: "post",
            cache: false,
            data:{"rowId":rowId},
            dataType:"json",
            async:false,
            success: function(data) {
                if (data == null) {
                    return;
                }
                $("#gameId").val(data.gameId);
                
                TagUtil.fillOptions('gameId');
                $("#tradeId").val(data.tradeId);
                $("#baseTypeId").val(data.baseTypeId);
                
                setAjxaUrl('bigTypeId', 'gameId'); 
                TagUtil.fillOptions('baseTypeId');
                
                setAjxaUrl('smallTypeId', 'gameId'); 
                $("#bigTypeId").val(data.bigTypeId);
                
                TagUtil.fillOptions('bigTypeId');
                $("#smallTypeId").val(data.smallTypeId);
                
                $("#ysLimit").val(data.ysLimit);
            }
        });
        $("#gameId").attr("disabled","true");
        $("#tradeId").attr("disabled","true");
        $("#baseTypeId").attr("disabled","true");
        $("#bigTypeId").attr("disabled","true");
        $("#smallTypeId").attr("disabled","true");
	}
})

var err = {'1':'添加','2':'修改'};
var action = {'1':'/save','2':'/update'};
function add(){
    var rowId = $('#rowId').val();
    var i;
    if (!CheckUtil.isNotNull(rowId) || rowId == 0) {
        i = 1;//添加
    } else {
        i = 2;//修改
    }
    var gameId = $.trim($("#gameId").val());
    if (!CheckUtil.isNotNull(gameId)) {
        layer.msg("请选择游戏!");
        return;
    }
    var gameName = $("#gameId").find("option:selected").text();
    $("#gameName").val(gameName);
    
    var tradeId = $.trim($("#tradeId").val());
    if (!CheckUtil.isNotNull(tradeId)) {
        layer.msg("请选择交易类型!");
        return;
    }
    var tradeName = $("#tradeId").find("option:selected").text();
    $("#tradeName").val(tradeName);

    var baseTypeId = $.trim($("#baseTypeId").val());
    if (!CheckUtil.isNotNull(baseTypeId)) {
        layer.msg("请选择主类!");
        return;
    }
    var baseTypeName = $("#baseTypeId").find("option:selected").text();
    $("#baseTypeName").val(baseTypeName);

    var bigTypeId = $.trim($("#bigTypeId").val());
    if (!CheckUtil.isNotNull(bigTypeId)) {
        layer.msg("请选择大类!");
        return;
    }
    var bigTypeName = $("#bigTypeId").find("option:selected").text();
    $("#bigTypeName").val(bigTypeName);

    var smallTypeId = $.trim($("#smallTypeId").val());
/*     if (!CheckUtil.isNotNull(smallTypeId)) {
        layer.msg("请选择小类!");
        return;
    } */
    $("#smallTypeName").val("");
    if (CheckUtil.isNotNull(smallTypeId)) {
        var smallTypeName = $("#smallTypeId").find("option:selected").text();
        $("#smallTypeName").val(smallTypeName);
    }
    
    var ysLimit = $("#ysLimit").val();
    if (!(parseFloat(ysLimit) > 0) ) {
        layer.msg("请填写正确的到账时间!");
        return;
    }
    
    //loading层
    var index = layer.load(0, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
    });
    $.ajax({
        url: "${tradeV1}/tradeBaseToAccountSafetyConfig" + action[i],
        type: "post",
        cache: false,
        data: new FormData($("#saveAndUpdateFrom")[0]),
        dataType:"json",
        processData: false,
        contentType: false,
        async:false,
        success: function(data) {
            layer.close(index);
            if(data.code == 0){
                parent.layer.msg("添加成功！");
            } else if(data.code == 1){
                parent.layer.msg("修改成功！");
            } else if(data.code == "-2"){
                parent.window.location.href="${sysManagerV1}/";
            } else {
                parent.layer.msg(data.message);
            }
            if(data.code >= 0){
                parent.findData();
                parent.layer.close(parent.tableIndex);
            }
        }
    });
}

//给目标select的ajaxURL 加参数
function setAjxaUrl(keyId, valueId){
    var gameId = $("#" + valueId).find("option:selected").val();
    var ajaxURL = $("#" + keyId).attr("ajaxURL");
    if(ajaxURL.indexOf("GAME_ID") < 0){
        ajaxURL += "&wm[GAME_ID]=" + gameId;
    } else {
        var valueTemp = ajaxURL.substring(ajaxURL.indexOf("wm[GAME_ID]="));
        if(valueTemp.indexOf("&") >= 0){
            valueTemp = valueTemp.substr(valueTemp.indexOf("=") + 1, valueTemp.indexOf("&"));
        }
        ajaxURL = ajaxURL.replace(valueTemp, "wm[GAME_ID]=" + gameId);
    }
    $("#" + keyId).attr("ajaxURL", ajaxURL);
}
</script>
</html>